<?php
use yii\grid\GridView;
use yii\helpers\Html;
use yii\helpers\Url;
use backend\utils\XHtml;

/* @var $this yii\web\View */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = '栏目管理';
$this->params['breadcrumbs'][] = $this->title;
?>
<?php $this->beginBlock('content-header'); ?>
<?= $this->title . ' ' . XHtml::create('栏目') ?>
<?php $this->endBlock(); ?>
<div class="box box-primary">
    <div class="box-body">
        <?= backend\widgets\grid\TreeGrid::widget([
            'dataProvider' => $dataProvider,
            'keyColumnName' => 'id',
            'parentColumnName' => 'parent_id',
            'parentRootValue' => '0',
            'pluginOptions' => [
                'initialState' => 'expanded',
            ],
            'columns' => [
                'name',
                'alias',
                [
                    'label' => '类型',
                    'value' => function ($model) {
                        return $model::getType($model['type']);
                    }
                ],
                [
                    'class' => 'backend\widgets\grid\PositionColumn',
                    'attribute' => 'sort'
                ],
                [
                    'class' => 'yii\grid\ActionColumn',
                    'template' => '{create} &nbsp;&nbsp; {update} &nbsp;&nbsp; {delete}',
                    'buttons' => [
                        'create' => function ($url, $model, $key) {
                            return Html::a('<i class="fa fa-plus"></i>', ['create', 'parent_id' => $model->id], ['class' => 'btn btn-xs btn-default', 'data-toggle' => 'tooltip', 'title' => '添加子分类']);
                        }
                    ]
                ],
            ],
        ]); ?>
    </div>
</div>